<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>获取input输入框的内容</title>
</head>
<body>
<input type="text" id="input1"><button onclick="print()">获取</button>
<script>
    function print() {
        text = document.querySelector("#input1").value
        alert(text)
    }
</script>
</body>
</html>